
import 'package:favorcate/core/model/category_model.dart';
import 'package:favorcate/core/model/meal_model.dart';
import 'package:favorcate/core/services/http_request.dart';
import 'package:favorcate/core/services/http_url.dart';

class JKRequestModel {

  // 1、美食分类
  static Future<List<JKCategoryModel>> getFoodCategory() async {
    // 网络请求
    final url = kHomeCategoryUrl;
    final result = await HttpRequest.get(url);

    // json 转model
    final category = result['category'];
    List<JKCategoryModel> categorys = [];
    for (var json in category) {
      categorys.add(JKCategoryModel.fromJson(json));
    }

    return categorys;
  }

  // 2、首页美食详情
  static Future<List<JKHomeMealModel>> getMealData() async {
    // 1.发送网络请求
    final url = kHomeMealUrl;
    final result = await HttpRequest.get(url);

    // 2.json转model
    final mealArray = result['meal'];
    List<JKHomeMealModel> meals = [];
    for (var json in mealArray) {
      meals.add(JKHomeMealModel.fromJson(json));
    }

    return meals;
  }
}